/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ViewTutor.java
 *
 * Created on 07 7, 12, 11:52:30 AM
 */
package monitor;

import java.awt.Color;
import java.awt.Component;
import javax.swing.JOptionPane;
import javax.swing.table.JTableHeader;
import java.awt.Container;
import java.sql.SQLException;

/**
 *
 * @author Charles
 */
public class ViewTutor extends javax.swing.JFrame {

    String mode = "Edit";
    String num;
    Long temp;
    private Component frame;
    private Container c;
    /** Creates new form ViewTutor */
    public ViewTutor() {
        initComponents();
        refresh();
        c = getContentPane();
        c.setBackground(Color.white);
        
    }
    
    private void refresh(){
        QHandler queryHandler = new QHandler();
        DBManager dbconnector = new DBManager();
        dbconnector.Connect();
        queryHandler.viewTutor();
        dbconnector.Pull(queryHandler.query);
        tutorTable.setModel(dbconnector.dTableModel);
        dbconnector.Disconnect(dbconnector.rs);
        
        editList.removeAllItems();
        editList.addItem("");
        
        tutorTable.setGridColor(Color.green);
        JTableHeader header = tutorTable.getTableHeader();
        header.setBackground(Color.green);
        
        QHandler queryHandler1 = new QHandler();
        DBManager dbconnector1 = new DBManager();
        dbconnector1.Connect();
        queryHandler1.selectIdNumTutor();
        dbconnector1.PullInfo(queryHandler1.query, mode);
        dbconnector1.Disconnect(dbconnector1.rs);
        
        tutorTable.getColumnModel().getColumn(0).setHeaderValue("ID Number");
        tutorTable.getColumnModel().getColumn(1).setHeaderValue("Name");
        tutorTable.getColumnModel().getColumn(2).setHeaderValue("Degree Program");
        
        QHandler queryHandler2 = new QHandler();
        DBManager dbconnector2 = new DBManager();
        dbconnector2.Connect();
        queryHandler2.viewTotalTutor();
        dbconnector2.getInfo(queryHandler2.query);
        
        try{
            
          temp = dbconnector2.rs.getLong("total");
          num = temp.toString();
             
        tutorTotal.setText(num);
        }catch(SQLException ex){}
        
         dbconnector2.Disconnect(dbconnector2.rs);
    }
    

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        tutorTable = new javax.swing.JTable();
        BtnClose = new javax.swing.JButton();
        BtnUpdate = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        editList = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        BtnInfo = new javax.swing.JButton();
        BtnDelete = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        tutorTotal = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("View Tutor Profile");

        tutorTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "ID No.", "Name", "Degree Program"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, true
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(tutorTable);

        BtnClose.setFont(new java.awt.Font("Modern No. 20", 0, 18));
        BtnClose.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pictures/Cancel.png"))); // NOI18N
        BtnClose.setText("Close");
        BtnClose.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtnCloseActionPerformed(evt);
            }
        });

        BtnUpdate.setFont(new java.awt.Font("Modern No. 20", 0, 18));
        BtnUpdate.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pictures/update.png"))); // NOI18N
        BtnUpdate.setText("Update");
        BtnUpdate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtnUpdateActionPerformed(evt);
            }
        });

        jLabel1.setText("SELECT ID NUMBER");

        jLabel2.setText("VIEW TUTOR");

        BtnInfo.setFont(new java.awt.Font("Modern No. 20", 0, 18));
        BtnInfo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pictures/moreinfo.png"))); // NOI18N
        BtnInfo.setText("More Info");
        BtnInfo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtnInfoActionPerformed(evt);
            }
        });

        BtnDelete.setFont(new java.awt.Font("Modern No. 20", 0, 18));
        BtnDelete.setIcon(new javax.swing.ImageIcon(getClass().getResource("/pictures/delete.png"))); // NOI18N
        BtnDelete.setText("Delete");
        BtnDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BtnDeleteActionPerformed(evt);
            }
        });

        jLabel3.setText("TOTAL # OF TUTORS");

        tutorTotal.setText("NUM");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(BtnUpdate)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(BtnInfo)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(BtnDelete)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(BtnClose))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 641, Short.MAX_VALUE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(editList, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 211, Short.MAX_VALUE)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tutorTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 241, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1)
                        .addComponent(editList, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(tutorTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(29, 29, 29)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(BtnDelete, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(BtnUpdate, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(BtnInfo)
                    .addComponent(BtnClose, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {BtnClose, BtnDelete, BtnInfo, BtnUpdate});

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void BtnCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnCloseActionPerformed
// TODO add your handling code here:
    ViewOptions view = new ViewOptions();
    view.setVisible(true);
    view.setLocationRelativeTo(null);
    this.dispose();
    
}//GEN-LAST:event_BtnCloseActionPerformed

private void BtnUpdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnUpdateActionPerformed
// TODO add your handling code here:
     if(editList.getSelectedItem().toString().equals("")){
        JOptionPane.showMessageDialog(frame,
        "Database might be empty or you selected an invalid value",
        "Cannot process request",
        JOptionPane.WARNING_MESSAGE);
    }
    
    else{
    
    UpdateTutor updateTutor = new UpdateTutor();
    updateTutor.TutorID = editList.getSelectedItem().toString();
    updateTutor.Update();
    updateTutor.setVisible(true);
    updateTutor.setLocationRelativeTo(null);
    this.dispose();
    
     }
}//GEN-LAST:event_BtnUpdateActionPerformed

private void BtnInfoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnInfoActionPerformed
// TODO add your handling code here:
     if(editList.getSelectedItem().toString().equals("")){
        JOptionPane.showMessageDialog(frame,
        "Database might be empty or you selected an invalid value",
        "Cannot process request",
        JOptionPane.WARNING_MESSAGE);
    }
    
    else{
    
    ViewTutorInfo view = new ViewTutorInfo();
    view.TutorID = editList.getSelectedItem().toString();
    view.View();
    view.setVisible(true);
    view.setLocationRelativeTo(null);
     }
}//GEN-LAST:event_BtnInfoActionPerformed

private void BtnDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnDeleteActionPerformed
// TODO add your handling code here:
     if(editList.getSelectedItem().toString().equals("")){
        JOptionPane.showMessageDialog(frame,
        "Database might be empty or you selected an invalid value",
        "Cannot process request",
        JOptionPane.WARNING_MESSAGE);
    }
    
    else{
    
    Delete delTutor = new Delete();
    delTutor.TutorID = editList.getSelectedItem().toString();
    delTutor.DeleteTutor();
    refresh();
     }
}//GEN-LAST:event_BtnDeleteActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ViewTutor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ViewTutor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ViewTutor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ViewTutor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new ViewTutor().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BtnClose;
    private javax.swing.JButton BtnDelete;
    private javax.swing.JButton BtnInfo;
    private javax.swing.JButton BtnUpdate;
    public static javax.swing.JComboBox editList;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tutorTable;
    private javax.swing.JLabel tutorTotal;
    // End of variables declaration//GEN-END:variables
}
